package com.zhentao.day05;



public class Pet {
  String name;
  int age;

  public Pet(String name, int age) {
    super();// 调用父类构造器。  new Object()
    this.name = name;
    this.age = age;
  }

  public void eat() { }

  public static void main(String[] args) {
    Feeder feeder = new Feeder();
    // Dog dog = new Dog("小黑", 4);
    Pet pet = new Dog("小黑",5);  // 向上转型  1.继承 2.对父类的方法进行重写 .
    Pet pet1 = new Monkey();
    feeder.eat(pet);
  }
}
    /* Feeder feeder = new Feeder() ;
    // Cat cat = new Cat("小花",3);
    Pet pet = new Cat("小花",4);
    feeder.feed(pet);

    // Dog dog = new Dog("小黑",4);
    Pet pet1 = new Dog("小黑",4);
    feeder.feed(pet1);*/

    // Pet pet2 = new Monkey();
    // Monkey monkey = new Monkey();
    // feeder.feed(monkey);


class Dog extends Pet {
  public Dog(String name, int age) {
    // super();  // 因为Pet类已经显式将构造器声明为有参构造器, 所以,默认构造器就不再提供。
    //子类继承父类, 构造器中, 默认的 super() ; 需要调用父类的 空构造器, 因为父类没有, 所以此时报错。
    super(name, age); // new 父类。 new Pet(name , age ) ;
  }

  @Override
  public void eat() {
    System.out.println("Dog ... eat ... ");
  }
}

class Cat extends Pet {
  public Cat(String name, int age) {
    super(name, age);
  }

  @Override
  public void eat() {
    System.out.println("Cat ... eat");
  }
}
// 编译时多态
/*class Feeder {
  public void feed (Dog dog){
    dog.eat();
  }

  public void feed(Cat cat) {
    cat.eat();
  }
}*/

/*class Feeder {
  public void feed (Pet pet){
    pet.eat();
  }
}*/
class Monkey extends Pet {

  public Monkey() {
    super("孙悟空",500);
  }

  public void eat() {
    System.out.println("Monkey ... eat");
  }
}
